package _go

func strStr(haystack string, needle string) int {
	l1 := len(haystack)
	l2 := len(needle)
	//查找的字段为空 直接返回0
	if l2 == 0 {
		return 0
	}
	//错误的出入
	if l1 == 0 || l1 < l2 {
		return -1
	}

	//整体比较 向后查找
	for i := 0; i <= l1-l2; i++ {
		if haystack[i:l2+i] == needle {
			return i
		}
	}
	return -1
}
